
// DmViewerDoc.cpp : implementation of the CDmViewerDoc class
//

#include "stdafx.h"
#include "DmViewer.h"

#include "DmViewerDoc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CDmViewerDoc

IMPLEMENT_DYNCREATE(CDmViewerDoc, CDocument)

BEGIN_MESSAGE_MAP(CDmViewerDoc, CDocument)
END_MESSAGE_MAP()


// CDmViewerDoc construction/destruction

CDmViewerDoc::CDmViewerDoc()
{
	// TODO: add one-time construction code here
	m_pDicomImage = NULL;
}

CDmViewerDoc::~CDmViewerDoc()
{
	if(NULL != m_pDicomImage)
	{
		delete m_pDicomImage;
	}
}

BOOL CDmViewerDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}

DicomImage* CDmViewerDoc::GetDicomImage()
{
	return m_pDicomImage;
}

// CDmViewerDoc serialization

void CDmViewerDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}


// CDmViewerDoc diagnostics

#ifdef _DEBUG
void CDmViewerDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CDmViewerDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG


// CDmViewerDoc commands

BOOL CDmViewerDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
	if (!CDocument::OnOpenDocument(lpszPathName))
		return FALSE;

	// TODO:  Add your specialized creation code here

		if(NULL != m_pDicomImage)
	{
		delete m_pDicomImage;
	}

	m_pDicomImage = new DicomImage(lpszPathName);
	UpdateAllViews(NULL); 

	return TRUE;
}
